package info.douyi.dps.controller;

import info.douyi.dps.model.PreviewImg;
import info.douyi.dps.service.PreviewImgService;
import info.douyi.dps.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/ImgDetail")
public class PreviewImgController {

    @Autowired
    private PreviewImgService previewImgService;

    @GetMapping("/getAllImg")
    public Result<List<String>> getAllImg(@RequestParam int id) {
        List<String> allImg = previewImgService.getImgListByPestId(id);

        if (allImg == null || allImg.isEmpty()) {
            // 创建新列表并添加默认图片
            allImg = new ArrayList<>();
            allImg.add("https://img.douyi.info/front-end/%E6%9A%82%E6%97%A0%E5%9B%BE%E7%89%87%20%281%29.png");
        }

        return Result.success(allImg);
    }

    @PostMapping("/ImgDetail")
    public Result addImg(@RequestBody PreviewImg previewImg) {
        previewImgService.addImage(previewImg);
        return Result.success();
    }
}
